//
//  TravelViewController.m
//  ToWhere
//
//  Created by dllo on 15/11/12.
//  Copyright © 2015年 www.TE.com. All rights reserved.
//

#import "TravelViewController.h"
#import "TravelAreaCollectionViewCell.h"
#import "TravelView.h"
#import "HeaderOneCollectionReusableView.h"
#import "HeaderTwoCollectionReusableView.h"
#import "TravelModel.h"
#import "TraveAreaModel.h"
#import "DataAnalysis.h"
#import "TravelTopicMoreViewController.h"
#import "TeavelTopicDetailsViewController.h"
#import "TravelAreaDetailsViewController.h"
#import "TravelSearchViewController.h"
#import "CoreDatamanager.h"
#import "Citys.h"
#import <CoreLocation/CoreLocation.h>
#import "WeatherDetailsViewController.h"
#define Travel_TOPIC_URL @"http://chanyouji.com/api/articles.json?page=1"
#define Travel_Area_URL @"http://chanyouji.com/api/destinations.json?page=1"
@interface TravelViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UITextFieldDelegate,CLLocationManagerDelegate>

//创建collectionview
@property (nonatomic, retain) UICollectionView *collectionView;
//创建自定义视图
@property (nonatomic, retain) TravelView *travelView;

@property (nonatomic, retain) UIView *titleView;

@property (nonatomic, retain) UILabel *areaLabel;

@property (nonatomic, retain) UIButton *searchBtn;

@property (nonatomic, retain) UITextField *textField;
//国内外数组
@property (nonatomic, retain) NSArray *nationArr;
//国内数组
@property (nonatomic, retain) NSArray *chinaArr;

//专题的数组
@property (nonatomic, retain) NSMutableArray *topicArray;
//地区大叔=书组
@property (nonatomic, retain) NSMutableArray *areaArray;
//地区小数组
@property (nonatomic, retain) NSMutableArray *arrayArea;

@property (nonatomic, retain) CoreDatamanager *coreDataManage;

@property (nonatomic, retain) CLLocationManager *locationmanager;

@property (nonatomic, retain) UIImageView *locationImage;

@property (nonatomic, retain) UILabel *locationLabel;

@property (nonatomic, copy) NSString *locatonArea;

@property (nonatomic, retain) UILabel *leftLabel;

@property (nonatomic, retain) UIButton *weather;

@property (nonatomic, retain) UILabel *weatherLabel;

@property (nonatomic, retain) UILabel *tmpLabel;

@property (nonatomic, retain) UIImageView *imageDu;
@end

@implementation TravelViewController

-(void)dealloc
{
    [_collectionView release];
    [_travelView release];
    [_nationArr release];
    [_chinaArr release];
    [_arrayArea release];
    [_topicArray release];
    [_areaArray release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.coreDataManage = [CoreDatamanager shareManager];
    //开始定位
    [self initLocation];
    self.arrayArea = [NSMutableArray array];
    self.areaArray = [NSMutableArray array];
    self.topicArray = [NSMutableArray array];
    self.nationArr = @[@"国内",@"0",@"国外"];
      self.chinaArr = @[@"台港澳", @"大陆", @"亚洲",@"欧洲", @"美洲、大洋洲、非洲与南极洲"];
    
    self.view.backgroundColor = [UIColor whiteColor];
   
//    if ([DataAnalysis networkReachabilityStatus] == AFNetworkReachabilityStatusNotReachable ) {
//        //读取缓存
//        [self gain];
//    }
//    else
//    {
        //网络请求
        [self getRequst];
//    }
    
    //创建collectionView视图
    [self createCollectionView];
    
    //创建自定义视图
    [self createTravelView];
    
    //天气数据请求
    [self gainData];
  }


- (void)gain{

    NSString *cachesPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject;
    NSString *Caches = [cachesPath stringByAppendingPathComponent:@"CachesField"];
    NSString *folderPath = [Caches stringByAppendingString:@"SYLXD.plist"];

    for (NSDictionary *dic in [NSKeyedUnarchiver unarchiveObjectWithFile:folderPath]) {
        TravelModel *model = [[TravelModel alloc] initWithNSDictionary:dic];
        if ([model.category isEqualToString:@"99"]) {
            [self.areaArray insertObject:model atIndex:0];
        } else if ([model.category isEqualToString:@"999"]){
            [self.areaArray insertObject:model atIndex:1];
        } else{
            [self.areaArray addObject:model];
        }
        
    }
   [self.collectionView reloadData];
    
}
//网络请求
-(void)getRequst
{
    [DataAnalysis dataAnalysisGETWithUrlString:Travel_Area_URL parameters:nil showHuD:YES hiddenView:nil successfulBlock:^(id responseObject) {
        
        NSString *cachesPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject;
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSString *Caches = [cachesPath stringByAppendingPathComponent:@"CachesField"];
        [fileManager createDirectoryAtPath:Caches withIntermediateDirectories:YES attributes:nil error:nil];
        NSString *folderPath = [Caches stringByAppendingString:@"SYLXD.plist"];
        [NSKeyedArchiver archiveRootObject:responseObject toFile:folderPath];
        
        NSArray * array = responseObject;
        
        for (NSDictionary *dic in array) {
            TravelModel *model = [[TravelModel alloc] initWithNSDictionary:dic];
            if ([model.category isEqualToString:@"99"]) {
                [self.areaArray insertObject:model atIndex:0];
            } else if ([model.category isEqualToString:@"999"]){
                [self.areaArray insertObject:model atIndex:1];
            } else{
                [self.areaArray addObject:model];
            }
           
        }
  
         [self.collectionView reloadData];
    } failureBlock:^(NSError *error) {
        NSLog(@"error: %@", error);
    }];
}
- (void)gainData{
    NSString *urlString = [NSString stringWithFormat:@"http://tq.91.com/api/?act=107&pid=115&word=%@ &osv=8.1&dm=iPhone5,3&chl=otSy9Zonl/k5CTkt33reOQ==&sv=3.13.0&spid=1&nt=10&imei=D3BF9AF1-1DF9-4B08-86CB-F4CB972E3DF0&mt=1",[self.locationLabel.text substringToIndex:self.locationLabel.text.length - 1]];
    
    NSString *beijingString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    [DataAnalysis dataAnalysisGETWithUrlString:beijingString parameters:nil showHuD:NO hiddenView:nil successfulBlock:^(id responseObject)
     {
         NSDictionary *dic = responseObject;
         NSString *str = [NSString stringWithFormat:@"http://tq.91.com/api/?chl=otSy9Zonl%@&city=%@&spid=1&productid=8032&osv=8.1&imei=D3BF9AF1-1DF9-4B08-86CB-F4CB972E3DF0&cityname=%@&vercode=3.13.0&dm=%@",@"%2Fk5CTkt33reOQ%3D%3D",[[[dic objectForKey:@"items"] firstObject] objectForKey:@"id"],@"%E7%93%A6%E6%88%BF%E5%BA%97",@"iPhone5%2C3&sv=3.13.0&option=now,weather,tqzs,tqyj,sun,pm,wind&act=215&pid=115&chkcode=9c122cd2f020dd001c4e30f00c4218a3&nt=10&mt=1"];
         [DataAnalysis dataAnalysisGETWithUrlString:str parameters:nil showHuD:NO hiddenView:nil successfulBlock:^(id responseObject) {
             NSDictionary *data = responseObject;
             self.tmpLabel.text = [[data objectForKey:@"now"] objectForKey:@"temp"];
             self.imageDu.frame = CGRectMake(20 *kWidth + self.tmpLabel.text.length * 20 *kWidth, 0, 25 *kWidth, 25 *kHeight);
             self.weatherLabel.text = [[[data objectForKey:@"weatherinfo"] objectForKey:@"weather"][1]objectForKey:@"dayweather"];
             
         } failureBlock:^(NSError *error) {
             
         }];
         
     } failureBlock:^(NSError *error) {
         
     }];
    
}

#pragma mark 创建自定义视图
-(void)createTravelView
{
    self.travelView = [[TravelView alloc]initWithFrame:CGRectMake(0, -350 * kHeight, self.view.frame.size.width, 350 * kHeight)];
    
    [self.travelView.leftBtn addTarget:self action:@selector(moreBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.travelView.bigBtn addTarget:self action:@selector(moreBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.travelView.rightBtn addTarget:self action:@selector(moreBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.travelView.moreBtn addTarget:self action:@selector(moreBtnAction:) forControlEvents:UIControlEventTouchUpInside];
      [self.collectionView addSubview:self.travelView];
    
    [_travelView release];
    
    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"4.jpg"]];
    image.frame = CGRectMake(0, - 680 * kHeight, 375 *kWidth, 310 *kHeight);
    image.userInteractionEnabled = YES;
    [self.collectionView addSubview:image];
    
    self.titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0 *kHeight, 375 *kWidth, 64 *kHeight)];
    self.titleView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:self.titleView];
    
    self.areaLabel = [[UILabel alloc] initWithFrame:CGRectMake(70 *kWidth, 20 *kHeight, 235 *kWidth, 40 *kHeight)];
    self.areaLabel.font = [UIFont systemFontOfSize:20 *kWidth];
    self.areaLabel.textColor = [UIColor whiteColor];
    self.areaLabel.textAlignment = NSTextAlignmentCenter;
    [self.titleView addSubview:_areaLabel];
    
    self.searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.searchBtn.frame = CGRectMake(335 *kWidth, 25 *kHeight, 30 *kWidth, 30 *kHeight);
    [self.searchBtn setImage:[UIImage imageNamed:@"iconfont-sousuo"] forState:UIControlStateNormal];
    [self.searchBtn addTarget:self action:@selector(searchPush) forControlEvents:UIControlEventTouchUpInside];
    self.searchBtn.alpha = 0;
    [self.titleView addSubview:_searchBtn];
    
    UIButton *btn  = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(80 *kWidth, -450 *kHeight, 215 *kWidth, 30 *kHeight);
    btn.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.3];
    [btn setTitle:@"🔍搜索目的地、游记..." forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:17 * kWidth];
    btn.layer.borderColor = [UIColor whiteColor].CGColor;
    btn.layer.borderWidth = 0.5;
    btn.layer.cornerRadius = 7;
    [btn addTarget:self action:@selector(searchPush) forControlEvents:UIControlEventTouchUpInside];
    [self.collectionView addSubview:btn];
    
    
    self.locationLabel = [[UILabel alloc] initWithFrame:CGRectMake(35 *kWidth, 275 *kHeight, 150 *kWidth, 25 *kHeight)];
    self.locatonArea = @"北京市";
    self.locationLabel.text = self.locatonArea;
    self.locationLabel.textColor = [UIColor whiteColor];
    self.locationLabel.font = [UIFont systemFontOfSize:17 *kWidth];
    [image addSubview:_locationLabel];
    [_locationLabel release];
    self.locationImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"weather_dingwei"]];
    self.locationImage.frame = CGRectMake(0 *kWidth, 275 *kHeight, 30 *kWidth, 25 *kHeight);
    [image addSubview:_locationImage];
    [_locationLabel release];

    self.leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 *kWidth, 20 *kHeight, 120 *kWidth, 30 *kHeight)];
    self.leftLabel.textColor = [UIColor whiteColor];
    self.leftLabel.text = @"北京";
    self.leftLabel.alpha = 0;
    self.leftLabel.font = [UIFont systemFontOfSize:17 *kWidth];
    [_titleView addSubview:_leftLabel];
    
    self.weather = [UIButton buttonWithType:UIButtonTypeCustom];
    self.weather.frame = CGRectMake(220 *kWidth, 70  *kHeight, 150 *kWidth, 100 *kHeight);
    [self.weather addTarget:self action:@selector(weather:) forControlEvents:UIControlEventTouchUpInside];
    [image addSubview:_weather];
   
    self.tmpLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120 *kWidth, 70 *kHeight)];
    self.tmpLabel.font = [UIFont systemFontOfSize:50 *kWidth];
    self.tmpLabel.textColor = [UIColor whiteColor];
    [_weather addSubview:_tmpLabel];
    
    self.weatherLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 70 *kHeight, 150 *kWidth, 30 *kHeight)];
    self.weatherLabel.textColor = [UIColor whiteColor];
    self.weatherLabel.font = [UIFont systemFontOfSize:17 *kWidth];
    [_weather addSubview:_weatherLabel];
    
    self.imageDu = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"du1"]];
    [_weather addSubview:_imageDu];
}
- (void)initLocation{
    
    self.locationmanager = [[CLLocationManager alloc]init];
    [self.locationmanager setDesiredAccuracy:kCLLocationAccuracyBest];
    _locationmanager.distanceFilter = 100;
    [_locationmanager requestAlwaysAuthorization];//添加这句
    _locationmanager.delegate = self;
    NSLog(@"开始定位");
    [_locationmanager startUpdatingLocation];

}

#pragma mark CLLocation代理回调方法
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    
    [self.locationmanager stopUpdatingLocation];
    NSLog(@"location ok");
    NSLog(@"%@",[NSString stringWithFormat:@"经度:%3.5f\n纬度:%3.5f",newLocation.coordinate.latitude,newLocation.coordinate.longitude]);
    
    CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
    [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        
        for (CLPlacemark * placemark in placemarks) {
            
            NSDictionary *test = [placemark addressDictionary];
            //  Country(国家)  State(省) City(市) SubLocality(区)
            self.locatonArea = [test objectForKey:@"City"];
            self.locationLabel.text = self.locatonArea;
            self.leftLabel.text = self.locationLabel.text;
            [self gainData];
        }
    }];
}
#pragma mark Action
//#pragma mark 点击进入更多
-(void)moreBtnAction:(UIButton *)sender
{
    
    if (sender.tag == 10000) {
 
    TravelTopicMoreViewController *more = [[TravelTopicMoreViewController alloc]init];
    
        [self setHidesBottomBarWhenPushed:YES];
        
        [self.navigationController pushViewController:more animated:YES];

        [self setHidesBottomBarWhenPushed:NO];
   // [more release];
    }else{
        
        TeavelTopicDetailsViewController *view =[[TeavelTopicDetailsViewController alloc]init];
        
        view.idstring =(NSNumber *)(sender.tag - 10000);
        
        [self setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:view animated:YES];
        [self setHidesBottomBarWhenPushed:NO];
        
    }
}
//pushSearch
- (void)searchPush{

    TravelSearchViewController *search = [[TravelSearchViewController alloc] init];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:search animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}
- (void)weather:(UIButton *)btn{
    
    WeatherDetailsViewController *weather = [[WeatherDetailsViewController alloc] init];
    NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Citys"];
    NSArray *resultArray = [_coreDataManage.managedObjectContext executeFetchRequest:request error:nil];
    BOOL b = NO;
    if (resultArray.count == 0) {
        Citys *city = [NSEntityDescription insertNewObjectForEntityForName:@"Citys" inManagedObjectContext:_coreDataManage.managedObjectContext];
        city.cityName = [self.locationLabel.text substringToIndex:self.locationLabel.text.length - 1];
        [_coreDataManage saveContext];
    }
    else{
    for (Citys *city in resultArray) {
        
        if ([city.cityName isEqualToString:[self.locationLabel.text substringToIndex:self.locationLabel.text.length - 1]]) {
            NSLog(@"%@==%@",city.cityName,[self.locationLabel.text substringToIndex:self.locationLabel.text.length - 1]);
            b = YES;
            break;
        }else{
        
            b = NO;
        }
    }
    if (!b) {
        Citys *city = [NSEntityDescription insertNewObjectForEntityForName:@"Citys" inManagedObjectContext:_coreDataManage.managedObjectContext];
        city.cityName = [self.locationLabel.text substringToIndex:self.locationLabel.text.length - 1];
        [_coreDataManage saveContext];
    }
}
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:weather animated:YES];
    self.hidesBottomBarWhenPushed = NO;

    
}
#pragma mark 创建collectionView视图
-(void)createCollectionView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:layout];
    
    [self.collectionView setContentInset:UIEdgeInsetsMake(650 * kHeight, 0, 0, 0)];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
//    self.collectionView.scrollEnabled = NO;
    self.collectionView.bounces = NO;
    self.collectionView.showsVerticalScrollIndicator = NO;
    
    [self.view addSubview: self.collectionView];
    [layout release];
    [_collectionView release];
    

    [self.collectionView registerClass:[TravelAreaCollectionViewCell class] forCellWithReuseIdentifier:@"TravelAreaCollectionViewCell"];
    [self.collectionView registerClass:[HeaderOneCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderOneCollectionReusableView"];
        [self.collectionView registerClass:[HeaderTwoCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderTwoCollectionReusableView"];
}
#pragma mark collection代理回调
//#pragma mark 监控collectionView的偏移量
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

    CGFloat offset = scrollView.contentOffset.y;

 

  
    if (offset > - 500) {
        self.searchBtn.alpha = 1;
        self.leftLabel.alpha = 1;
    }else{
    
        self.searchBtn.alpha = 0;
        self.leftLabel.alpha = 0;
    }
    if (offset < -150){
    
        self.areaLabel.text = @"趣哪";
    }
    if (offset > -150 *kHeight && offset < 250 *kHeight) {
        self.areaLabel.text = @"台港澳";
    }
     if (offset > 250 *kHeight && offset < 2740 *kHeight){
    
        self.areaLabel.text = @"大陆";
    }
     if (offset > 2740 *kHeight && offset < 4250 *kHeight){
    
        self.areaLabel.text = @"亚洲";
    }
    if (offset > 4250 *kHeight && offset < 5530 *kHeight){
    
        self.areaLabel.text = @"欧洲";
    }
     if (offset > 5530 *kHeight){
    
        self.areaLabel.text = @"美洲 大洋洲 非洲 南极洲";
    }
    
    if (scrollView.contentOffset.y > 0) {
        return;
    }
    self.titleView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:(scrollView.contentOffset.y + 620) / 1200 + 0.2];
}
#pragma mark 返回cell
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    TravelAreaCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TravelAreaCollectionViewCell" forIndexPath:indexPath];
    if (self.areaArray.count != 0 ) {
        TraveAreaModel *temp = [[_areaArray[indexPath.section] array] objectAtIndex:indexPath.row];
        [cell setAreaModel:temp];
    }
    return  cell;
}

#pragma mark 返回分区数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 5;
}

#pragma mark 返回单元格大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    return CGSizeMake(self.view.frame.size.width / 2 - 10* kWidth, 200 * kHeight);
}
#pragma mark 返回单元格最小间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 10 * kWidth;
}
#pragma mark 返回单元格最小行间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 5 * kHeight;
}

#pragma mark 返回单元格数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (_areaArray.count) {
        TravelModel *temp = _areaArray[section];
        return temp.array.count;
    }
    return 0;
}

#pragma mark 单元格的点击事件
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    TravelAreaDetailsViewController  *view = [[TravelAreaDetailsViewController alloc]init];
    view.idNumber = [[[_areaArray[indexPath.section] array] objectAtIndex:indexPath.row] ID];
      [self setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:view animated:YES];
    
    [self setHidesBottomBarWhenPushed:NO];

    
}
#pragma mark 单元格距离四周的间距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 5 * kWidth, 5 * kHeight, 5 *kWidth);
}
#pragma mark 头视图
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    if (kind == UICollectionElementKindSectionHeader) {
        
        if (indexPath.section == 0) {
        
            HeaderOneCollectionReusableView * view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderOneCollectionReusableView" forIndexPath:indexPath];
            
            view.strTwo = self.chinaArr[indexPath.section];
            return view;
            
        }else{
            
            
            HeaderTwoCollectionReusableView *viewO = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderTwoCollectionReusableView" forIndexPath:indexPath];
            viewO.strTwo = self.chinaArr[indexPath.section];
            return viewO;
            
        }
        
    }else
        
    {
        return nil;
    }
   
}
#pragma mark 返回头视图的高度
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return CGSizeMake(0, 50 *kWidth);
    }
        return CGSizeMake(0, 40 * kWidth);
    
}


-(void)viewWillAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"抽屉关" object:self userInfo:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
